package com.apes.fa.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.frame.model.DutyCenter;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = FaAssetScrapItem.CONST_TABLE_NAME)
public class FaAssetScrapItem extends Model {

    public static final String CONST_TABLE_NAME = "fa_asset_scrap_item";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "资产报废毁损(明细)", padding = 8)
    @Comment("明细编号")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fa_card_id", referencedColumnName = "id")
    @Comment("资产卡片编号")
    private FaCard faCard;

    @Column(name = "asset_type")
    @Comment("资产类型")
    private String assetType;

    @Column(name = "product_id")
    @Comment("商品卡片编号")
    private String productId;

    @Column(name = "product_name")
    @Comment("商品名称")
    private String productName;

    @Column(name = "dept_name")
    @Comment("部门名称")
    private String deptName;

    @Column(name = "asset_whereabouts")
    @Comment("资产去向")
    private String assetWhereabouts;

    @Column(name = "clean_cost")
    @Comment("清理费用")
    private double cleanCost;

    @Column(name = "residual_value_income")
    @Comment("残值收入")
    private double residualValueIncome;

    @Column(name = "scrap_reason")
    @Comment("报废原因")
    private String scrapReason;

    @Column(name = "decrease_reason")
    @Comment("原因")
    private String decreaseReason;

    @Column(name = "use_department_opinion")
    @Comment("使用部门意见")
    private String useDepartmentOpinion;

    @Column(name = "approve_department_opinion")
    @Comment("审批部门意见")
    private String approveDepartmentOpinion;

    @Column(name = "summary")
    @Comment("摘要")
    private String summary;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fa_asset_invest_id", referencedColumnName = "id")
    @Comment("资产报废毁损")
    private FaAssetScrap faAssetScrap;

    @Transient
    private String mid;
    public String getMid() {
        if(this.faAssetScrap.getId() != null) return this.faAssetScrap.getId();
        return null;
    }

    @Transient
    private String resolvePerson;

    public String getResolvePerson(){
        if(this.faAssetScrap.getApproveUid() != null) return this.faAssetScrap.getApproveUid().getName();
        return null;
    }

    @Transient
    private String resolveDate;

    public String getResolveDate(){
        if(this.faAssetScrap.getApproveDate() != null) return this.faAssetScrap.getApproveDate().toString();
        return null;
    }



}
